import { Paster, WithPasterList, ENUM_PASTER, NumberTransOption } from "qqlx-core";

import { PasterSchema } from "@/pond";
import { doRegularZhSort } from "@lib/com.list";
import { toString } from "@lib/com.verify";

export const table_w_xs = "w-32 min-w-32 max-w-32";
export const table_w_sm = "w-40 min-w-40 max-w-40";
export const table_w_md = "w-48 min-w-48 max-w-48";
export const table_w_lg = "w-64 min-w-64 max-w-64";
export const table_w_xl = "w-80 min-w-80 max-w-80";

/** labelStr -> withPasterTempList */
export function getAssetDataBefore(option?: { labelStr: string }): WithPasterList {
  return {
    withPasterTempList: toString(option?.labelStr)
      .split("；")
      .filter((d) => !!d)
      .map((name) => ({ ...new PasterSchema(), name })),
  };
}

/** withPasterTempList -> labelStr */
export function getAssetDataAfter(input?: Partial<WithPasterList>): { labelStr: string } {
  const pasterLs = input?.withPasterTempList || [];
  return { labelStr: doRegularZhSort(pasterLs.map((p: Paster) => p.name)).join("；") };
}

export const MAP_ENUM_PASTER = new Map<ENUM_PASTER, NumberTransOption & { icon?: string }>();

MAP_ENUM_PASTER.set(ENUM_PASTER.NONE, { value: ENUM_PASTER.NONE, zh: "标签异常", icon: "not_interested" });
MAP_ENUM_PASTER.set(ENUM_PASTER.CORP, {
  value: ENUM_PASTER.CORP,
  zh: "我的公司",
  icon: "maps_home_work",
  message: "正在经营的公司名称，主要用于开具订单、财务记账",
});
MAP_ENUM_PASTER.set(ENUM_PASTER.ESTATE, {
  value: ENUM_PASTER.ESTATE,
  zh: "厂房/仓库",
  icon: "gite",
  message: "对外开放中的厂房、仓库、办公室等",
});
MAP_ENUM_PASTER.set(ENUM_PASTER.FUND_ACCOUNT, {
  value: ENUM_PASTER.FUND_ACCOUNT,
  zh: "银行账户",
  icon: "assured_workload",
  message: "正在使用的银行账户，可以一键复制它的全部开户行信息",
});
MAP_ENUM_PASTER.set(ENUM_PASTER.NORMAL, {
  value: ENUM_PASTER.NORMAL,
  zh: "常用标签",
  icon: "bookmark",
  message: "主要用于标注订单、商品的产地、材质等各类信息",
});

export function getPasterTrans(type: ENUM_PASTER) {
  return MAP_ENUM_PASTER.get(type);
}

export function getPasterKeyTrans(type: ENUM_PASTER): Pick<Paster, "name" | "desc" | "content" | "remark"> {
  const trans = {
    name: "名称",
    desc: "简述",
    content: "具体内容",
    remark: "备注",
  };
  if (type === ENUM_PASTER.CORP) {
    trans.name = "公司名称";
    trans.desc = "公司联系方式";
    trans.content = "公司地址";
  } else if (type === ENUM_PASTER.ESTATE) {
    trans.name = "厂房/仓库名称";
    trans.desc = "厂房/仓库联系方式";
    trans.content = "厂房/仓库地址";
  } else if (type === ENUM_PASTER.FUND_ACCOUNT) {
    trans.name = "银行名称";
    trans.desc = "银行行号";
    trans.content = "账户名称";
    trans.remark = "账户号码";
  } else if (type === ENUM_PASTER.NORMAL) {
    trans.name = "标签名称";
  }
  return trans;
}
